package dp.最优解;

/**
 * todo
 *
 * @author songZiHao
 * @version 1.0.0
 * @ClassName 买卖股票的最佳时机ii122.java
 * @createTime 2024年03月07日 15:29:00
 */
public class 买卖股票的最佳时机ii122 {
	/*
   dp[i][k][0]=max(dp[i-1][k][0],dp[i-1][k-1][1]+prices[i])
   dp[i][k][1]=max(dp[i-1][k][1],dp[i-1][k-1][0]-prices[i])
   因为k为无限，所以不用管
	dp[i][0]=max(dp[i-1][0],dp[i-1][1]+prices[i])
   dp[i][1]=max(dp[i-1][1],dp[i-1][0]-prices[i])

   baseCase:
   dp[0][1]=-prices[1];
   dp[0][0]=0;
	*/
	public int maxProfit(int[] prices) {
		int length = prices.length;
		int[][] dp = new int[length][2];
		for (int i = 0; i < prices.length; i++) {
			if (i == 0) {
				dp[0][1] = -prices[i];
				dp[0][0] = 0;
				continue;
			}
			dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1] + prices[i]);
			dp[i][1] = Math.max(dp[i - 1][1], dp[i - 1][0] - prices[i]);
		}
		return dp[length - 1][0];
	}

	public static void main(String[] args) {
		System.out.println("abcdefg".substring(0,1));
	}
}
